<template>
  <view class="seek-page">
    <view class="card" v-for="(item,index) in dataList" :key="index" @click="handlerClick(item)">
      <view>
        <span>{{ item.asset_name }}</span>
        <span>
          <u-tag>{{ item.asset_state_name }}</u-tag>
        </span>
      </view>
      <view>
        <image :src="getImage(item.image)"/>
        <view>
          <view>
            <span>资产编号：{{ item.asset_code }}</span>
          </view>
          <view>
            <span>所属部门：{{ item.department_name }}</span>
          </view>
          <view>
            <span>存放区域：{{ item.location_name }}</span>
          </view>
          <view>
            <span>使用人：{{ item.user_name }}</span>
          </view>
        </view>
      </view>
      <view>
        <span>RFID：{{item.label_number}}</span>
      </view>
    </view>
  </view>
</template>

<script setup>
import request, {BASE_URL} from "@/api/request";

defineProps({
  dataList: {
    type: Array,
    default: () => []
  }
})

const handlerClick = (item) => {
  // let main = plus.android.runtimeMainActivity();
  // let Intent = plus.android.importClass("android.content.Intent");
  // let intent = new Intent(main.getIntent());
  // intent.setClassName(main, "com.rfid.lib.views.SeekActivity");
  // intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
  // intent.putExtra("item", JSON.stringify(item))
  // intent.putExtra("tokenKey", "Authorization")
  // intent.putExtra("token", request.getToken())
  // intent.putExtra("url", BASE_URL)
  // main.startActivity(intent);
  uni.navigateTo({
    url: '/pages/assetSeek/scan?item=' + JSON.stringify(item)
  })
}

const getItemType = (item) => {
  const idPattern = /^[a-zA-Z0-9-]+$/; // 包含字母、数字和 - 符号
  const apiPattern = /^\/File\//; // 假设接口地址以 '/File/' 开头
  const pathPattern = /^\/(?!File)/; // 普通路径以 '/' 开头，但不以 '/File/' 开头
  const relativePathPattern = /^[^/]/; // 假设相对路径不以 '/' 开头

  if (idPattern.test(item)) {
    return "ID";
  } else if (apiPattern.test(item)) {
    return "接口"; // 识别接口地址
  } else if (pathPattern.test(item)) {
    return "路径"; // 识别普通路径
  } else if (relativePathPattern.test(item)) {
    return "相对路径"; // 识别相对路径
  } else {
    return "其他";
  }
};

const getImage = (image) => {
  const type = getItemType(image);
  if (image) {
    if (type === "ID") {
      return `${BASE_URL}/File/GetImage?fileId=${image}`;
    } else {
      return image;
    }
  }
  return "";
};

</script>

<style scoped lang="scss">
.seek-page {
  width: 100%;

  .card {
    margin: 0 20rpx 40rpx 20rpx;
    padding: 20rpx;
    background-color: #fff;
    border-radius: 10rpx;

    &:first-child {
      margin-top: 40rpx;
    }

    > view:first-child {
      display: flex;

      > span:last-child {
        margin-left: auto;
      }
    }

    > view:nth-of-type(2) {
      color: #a9a9a9;
      display: flex;
      border-bottom: 1px solid #cccccc;
      padding: 15rpx 0;

      > image {
        height: 150rpx;
        width: 150rpx;
      }

      > view {
        padding: 0 15rpx;
        display: flex;
        flex-direction: column;
        font-size: .8rem;
      }
    }

    > view:nth-of-type(3) {
      margin-top: 15rpx;

      > span {
        color: #a9a9a9;
        font-size: .8rem;
      }
    }
  }
}
</style>